Completed
Push — master ( 6ac893...01672b )
by Alejandro
22s queued 10s
created

Home.componentDidMount   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
crap 1
1
import React, { useEffect } from 'react';
2
import { isEmpty, values } from 'ramda';
3
import { Link } from 'react-router-dom';
4
import PropTypes from 'prop-types';
5
import './Home.scss';
6
import ServersListGroup from '../servers/ServersListGroup';
7
8 1
const propTypes = {
9
  resetSelectedServer: PropTypes.func,
10
  servers: PropTypes.object,
11
};
12
13 1
const Home = ({ resetSelectedServer, servers: { list, loading } }) => {
14 3
  const servers = values(list);
15 3
  const hasServers = !isEmpty(servers);
16
17 3
  useEffect(() => {
18
    resetSelectedServer();
19
  }, []);
20
21 3
  return (
22
    <div className="home">
23
      <h1 className="home__title">Welcome to Shlink</h1>
24
      <ServersListGroup servers={servers}>
25
        {!loading && hasServers && <span>Please, select a server.</span>}
26
        {!loading && !hasServers && <span>Please, <Link to="/server/create">add a server</Link>.</span>}
27
        {loading && <span>Trying to load servers...</span>}
28
      </ServersListGroup>
29
    </div>
30
  );
31
};
32
33 1
Home.propTypes = propTypes;
34
35
export default Home;
36